<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   家居商家家装套餐控制器($小牛New $2014.07.28)*/

!defined('Q_PATH') && exit;

class JiajupackageController extends AController{

	public function init__(){
		$this->_arrNotMethod=array(
			'save_previewstatus',
			'save_preview',
			'view_preview',
			'foreverdelete_deep',
			'input_change_unique',
			'forbid',
			'resume',
			'clear_recycle',
			'save_sort'
		);
		
		parent::init__();
	}
	
	public function filter_(&$arrMap){
		$arrMap['A.jiajupackage_title']=array('like',"%".Q::G('jiajupackage_title')."%");
		$arrMap['A.jiajupackage_viewnum']=array('egt',intval(Q::G('jiajupackage_viewnum')));
		$arrMap['A.jiajucompany_id']=$GLOBALS['_company_']['jiajucompany_id'];
		if(Q::G('jiajupackage_price')){
			$arrMap['A.jiajupackage_price']=array('egt',Q::G('jiajupackage_price'));
		}
		
		// 添加时间
		$this->getTime_('A.create_dateline',$arrMap);
	}

	public function bEdit_(){
		$nId=intval(Q::G('id','G'));
		// 套餐内容
		$sContent=JiajupackagecontentModel::F('jiajupackage_id=?',$nId)->getColumn('jiajupackage_content');
		$this->assign('arrConfigData',json_decode($sContent,true));
		$this->assign('arrConfigTitle',json_decode($GLOBALS['_cache_']['jiaju_option']['package_config'],true));
	}

	protected function AEditObject_($oModel){
		if(in_array($oModel->jiajupackage_status,array(9,3)) || $oModel->jiajucompany_id!=$GLOBALS['_company_']['jiajucompany_id']){
			$this->E('你没有权限访问。');
		}
	}
	
	public function bAdd_(){
		$this->assign('arrConfigTitle',json_decode($GLOBALS['_cache_']['jiaju_option']['package_config'],true));
	}

	public function insert($sModel=null,$nId=null){
		$oJiajupackage=new JiajupackageModel();
		$oJiajupackage->saveData($GLOBALS['_company_']);
		if($oJiajupackage->isError()){
			$this->E($oJiajupackage->getErrorMessage());
		}

		$this->A($oJiajupackage->toArray(),'套餐添加成功',1);
	}

	public function update($sModel=null,$nId=null){
		$nId=intval(Q::G('id'));
		
		$oJiajupackage=JiajupackageModel::F('jiajupackage_id=?',$nId)->getOne();
		$oJiajupackage->updateData($GLOBALS['_company_']);
		if($oJiajupackage->isError()){
			$this->E($oJiajupackage->getErrorMessage());
		}

		$this->S('套餐更新成功');
	}

}
